<Project>
  <!-- Packaging projects (.pkgproj) are non-SDK-style, so they need to directly import Directory.Build.props -->
  <Import Project="..\Directory.Build.props" />
  <Import Project="$(NuGetPackageRoot)\microsoft.dotnet.build.tasks.packaging\$(MicrosoftDotNetBuildTasksPackagingVersion)\build\Microsoft.DotNet.Build.Tasks.Packaging.props" />
  <Import Project="$(NuGetPackageRoot)\microsoft.dotnet.build.tasks.templating\$(MicrosoftDotNetBuildTasksTemplatingVersion)\build\Microsoft.DotNet.Build.Tasks.Templating.props" />

  <PropertyGroup>
    <!-- Defined in Packaging.targets, but we need this before targets are imported -->
    <PackagePlatform Condition="'$(PackagePlatform)' == ''">$(Platform)</PackagePlatform>
    <PackagePlatform Condition="'$(PackagePlatform)' == 'amd64'">x64</PackagePlatform>
    <MinOSForArch>win7</MinOSForArch>
    <MinOSForArch Condition="'$(PackagePlatform)' == 'arm'">win8</MinOSForArch>
    <MinOSForArch Condition="'$(PackagePlatform)' == 'arm64'">win10</MinOSForArch>
    <PackagePlatform>AnyCPU</PackagePlatform>

    <PackageIndexFile>$(MSBuildThisFileDirectory)packageIndex.json</PackageIndexFile>

    <!-- coreclr doesn't currently use the index so don't force it to be in sync -->
    <SkipIndexCheck>true</SkipIndexCheck>
  </PropertyGroup>

  <!-- CoreCLR nuget packages shouldn't be published during servicing. -->
  <PropertyGroup Condition="'$(PreReleaseVersionLabel)' == 'servicing'">
    <IsShipping>false</IsShipping>
  </PropertyGroup>

  <ItemGroup>
    <PackageIndex Condition="'$(MSBuildProjectExtension)' == '.pkgproj'" Include="$(PackageIndexFile)" />
  </ItemGroup>

  <PropertyGroup>
    <!-- build the transport package which includes product and symbols in addition to standard packages
    This is a legacy setting as we tend to use symbol packages for symbol indexing and we don't use
    transport packages to flow dependencies anymore -->
    <CreatePackedPackage Condition="'$(CreatePackedPackage)' == ''">false</CreatePackedPackage>

    <SupportedPackageOSGroups Condition="'$(SupportedPackageOSGroups)' == ''">windows;osx;android;linux;freebsd;netbsd;illumos;solaris;haiku</SupportedPackageOSGroups>
    <SupportedPackageOSGroups>;$(SupportedPackageOSGroups);</SupportedPackageOSGroups>

    <_isSupportedOSGroup>true</_isSupportedOSGroup>
  </PropertyGroup>

  <!-- derive an OS Group based on the OS Family -->
  <PropertyGroup>
    <_derivedPackageTargetOSGroup Condition="'$(_derivedPackageTargetOSGroup)' == '' and '$(TargetOS)' != ''">$(TargetOS)</_derivedPackageTargetOSGroup>
    <_derivedPackageTargetOSGroup Condition="'$(_derivedPackageTargetOSGroup)' == ''">linux</_derivedPackageTargetOSGroup>

    <_isSupportedOSGroup Condition="!$(SupportedPackageOSGroups.Contains(';$(_derivedPackageTargetOSGroup);'))">false</_isSupportedOSGroup>
  </PropertyGroup>

  <!-- _packageTargetOSGroup is used to control the runtime package imports, don't import runtime package targets for
       an unsupported OS Group -->
  <PropertyGroup Condition="'$(PackageTargetRuntime)' != '' and '$(_isSupportedOSGroup)' == 'true'">
    <!-- Android will use Linux package definitions -->
    <_packageTargetOSGroup>$(_derivedPackageTargetOSGroup)</_packageTargetOSGroup>
    <_packageTargetOSGroup Condition="'$(_derivedPackageTargetOSGroup)' == 'android'">linux</_packageTargetOSGroup>
  </PropertyGroup>
  <PropertyGroup>
    <SkipPackageFileCheck>true</SkipPackageFileCheck>
    <OutputPath>$(PackageOutputPath)</OutputPath>
  </PropertyGroup>

  <PropertyGroup Condition="'$(IsLineupPackage)' == 'true'">
    <SkipValidatePackage>true</SkipValidatePackage>
    <IncludeRuntimeJson>true</IncludeRuntimeJson>
  </PropertyGroup>

  <ItemGroup Condition="$(SupportedPackageOSGroups.Contains(';linux;'))">
    <OfficialBuildRID Include="linux-x64" />
    <OfficialBuildRID Include="linux-musl-x64" />
    <OfficialBuildRID Include="rhel.6-x64" />
    <OfficialBuildRID Include="linux-arm">
      <Platform>arm</Platform>
    </OfficialBuildRID>
    <OfficialBuildRID Include="linux-musl-arm">
      <Platform>arm</Platform>
    </OfficialBuildRID>
    <OfficialBuildRID Include="linux-arm64">
      <Platform>arm64</Platform>
    </OfficialBuildRID>
    <OfficialBuildRID Include="linux-musl-arm64">
      <Platform>arm64</Platform>
    </OfficialBuildRID>
    <OfficialBuildRID Include="tizen.4.0.0-armel">
      <Platform>armel</Platform>
    </OfficialBuildRID>
    <OfficialBuildRID Include="tizen.5.0.0-armel">
      <Platform>armel</Platform>
    </OfficialBuildRID>
  </ItemGroup>
  <ItemGroup Condition="$(SupportedPackageOSGroups.Contains(';osx;'))">
    <OfficialBuildRID Include="osx-x64" />
    <OfficialBuildRID Include="osx-arm64">
      <Platform>arm64</Platform>
    </OfficialBuildRID>
  </ItemGroup>
  <ItemGroup Condition="$(SupportedPackageOSGroups.Contains(';freebsd;'))">
    <OfficialBuildRID Include="freebsd-x64" />
  </ItemGroup>
  <ItemGroup Condition="$(SupportedPackageOSGroups.Contains(';netbsd;'))">
    <OfficialBuildRID Include="netbsd-x64" />
  </ItemGroup>
  <ItemGroup Condition="$(SupportedPackageOSGroups.Contains(';illumos;'))">
    <OfficialBuildRID Include="illumos-x64" />
  </ItemGroup>
  <ItemGroup Condition="$(SupportedPackageOSGroups.Contains(';solaris;'))">
    <OfficialBuildRID Include="solaris-x64" />
  </ItemGroup>
  <ItemGroup Condition="$(SupportedPackageOSGroups.Contains(';haiku;'))">
    <OfficialBuildRID Include="haiku-x64" />
  </ItemGroup>
  <ItemGroup Condition="$(SupportedPackageOSGroups.Contains(';windows;'))">
    <OfficialBuildRID Include="win-x86">
      <Platform>x86</Platform>
    </OfficialBuildRID>
    <OfficialBuildRID Include="win-x64" />
    <OfficialBuildRID Include="win-arm64">
      <Platform>arm64</Platform>
    </OfficialBuildRID>
  </ItemGroup>
  <ItemGroup>
    <!-- Ensure we have a RID-specific package for the current build, even if it isn't in our official set, but
         don't build the RID-specific package if we're in an unsupported os family -->
    <BuildRID Include="@(OfficialBuildRID)" Exclude="$(OutputRID)"/>
    <BuildRID Include="$(OutputRID)"
              Condition="'$(_isSupportedOSGroup)' == 'true'">
      <Platform Condition="'$(TargetArchitecture)' == 'x64'">amd64</Platform>
      <Platform Condition="'$(TargetArchitecture)' != 'x64'">$(TargetArchitecture)</Platform>
    </BuildRID>
  </ItemGroup>

  <ItemGroup>
    <_project Include="@(BuildRID)">
      <Platform Condition="'%(Platform)' == ''">amd64</Platform>
      <PackageTargetRuntime>%(Identity)</PackageTargetRuntime>
      <AdditionalProperties>PackageTargetRuntime=%(Identity);Platform=%(Platform)</AdditionalProperties>
    </_project>

    <_buildRidProjects Include="@(_project->'$(MSBuildProjectName).pkgproj')" />
    <!-- Only include rid projects for a builds file, not for a lineup package -->
    <Project Condition="'$(IsLineupPackage)' != 'true'" Include="@(_buildRidProjects)" />
  </ItemGroup>

  <ItemGroup Condition="'$(IsLineupPackage)' == 'true'">
    <!-- Include project references for a lineup package to generate the runtime.json file -->
    <ProjectReference Include="@(_buildRidProjects)" />
  </ItemGroup>
</Project>
